package com.dyw.spzx.manager.controller;

import com.dyw.spzx.manager.service.ProductSpecService;
import com.dyw.spzx.model.entity.product.ProductSpec;
import com.dyw.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商品规格接口")
@RestController
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {

    @Autowired
    private ProductSpecService productSpecService;
    @Operation(summary = "查询所有商品规格")
    @GetMapping("findAll")
    public Result<List<ProductSpec>> findAll(){
        List<ProductSpec> productSpecList = productSpecService.findAll();
        return Result.ok(productSpecList);
    }



    @Operation(summary = "分页查询商品规格")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<ProductSpec>> findByPage(
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit) {
        PageInfo<ProductSpec> pageInfo = productSpecService.findByPage(page, limit);

        return Result.ok(pageInfo);
    }


    @Operation(summary = "添加商品规格")
    @PostMapping("/save")
    public Result save(@RequestBody ProductSpec productSpec) {
        productSpecService.save(productSpec);
        return Result.ok(null);
    }

    @Operation(summary = "修改商品规格")
    @PutMapping("/updateSpec")
    public Result updateSpec(@RequestBody ProductSpec productSpec) {
        productSpecService.updateSpec(productSpec);
        return Result.ok(null);
    }

    @Operation(summary = "删除商品规格")
    @DeleteMapping("/deleteSpec/{id}")
    public Result deleteSpec(@PathVariable("id") Long id) {
        productSpecService.deleteSpec(id);
        return Result.ok(null);
    }



}
